/*
Copyright (C) 2011 by Linden Liu and Dereck Leng

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package org.googlecode.voaonair.voaprovider.data
{
	import flash.display.Bitmap;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import org.googlecode.voaonair.contentprovider.IArticle;
	
	public class VOAArticle extends EventDispatcher implements IArticle
	{
		private var _title:String;
		private var _link:String;
		private var _description:String;
		private var _content:String;
		private var _pubDate:Date;
		private var _guid:uint;
		private var _creator:String;
		private var _category:String;
		private var _coverPage:Bitmap;
		private var _imgURLs:Array;
		private var _audioPath:String;
		private var _isRead:Boolean;
		
		private var coverPageUrl:String;
		public function VOAArticle(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		static public function fromXML(item:XML):IArticle
		{
			if ( ! item )
				return null;
			
			var article:VOAArticle = new VOAArticle();
			article._title = item.title;
			article._link = item.link;
			article._description = item.description;
			var content:Namespace = item.namespace("content");
			article._content = item.content::encoded;
			article._pubDate = new Date(Date.parse(item.pubDate));
			article._guid = uint(item.guid);
			var dc:Namespace = item.namespace("dc");
			article._creator = item.dc::creator;
			article._category = item.category;
			article.coverPageUrl = item.enclosure.@url;
			var media:Namespace = item.namespace("media");
			var medias:XMLList = item.media::group.media::content.(@medium=="image");
			article._audioPath = (item.media::group.media::content.(@medium=="audio"))[0].@url;
			article._isRead = false;
			return article as IArticle;
		}
		public function get title():String
		{
			return _title;
		}
		
		public function get link():String
		{
			return _link;
		}
		
		public function get description():String
		{
			return _description;
		}
		
		public function get content():String
		{
			return _content;
		}
		
		public function get pubDate():Date
		{
			return _pubDate;
		}
		
		public function get guid():uint
		{
			return _guid;
		}
		
		public function get creator():String
		{
			return _creator;
		}
		
		public function get category():String
		{
			return _category;
		}
		
		public function get coverPage():Bitmap
		{
			return null;
		}
		
		public function get imageURLs():Array
		{
			return null;
		}
		
		public function get audioPath():String
		{
			return _audioPath;
		}
		
		public function get isRead():Boolean
		{
			return _isRead;
		}
		
		public function set isRead(value:Boolean):void
		{
			_isRead = value;
		}
	}
}